<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/1 0001
 * Time: 下午 5:12
 */
namespace app\api\controller;

use app\api\model\Apptoken;
use app\common\auth\JwtAuth;
use app\common\BaseHelper;
use app\common\validate\LoginValidate;
use app\http\response\ResponseJson;
use think\Controller;
use think\Exception;
use think\facade\Request;
use think\facade\Config;

/**
 * 登录
 * Class Auth
 * @package app\api\controller
 */
class Auth extends Controller {

    use ResponseJson;

    /**
     * 超市收银端登录
     * @return \think\response\Json
     */
    public function login(){
        //return $this->jsonSuccessData(['name'=>"huanghe",'age'=>18]);
        //dump(\Yaconf::get('status.success'));

        (new LoginValidate())->goCheck();
        if(Request::isPost()){
            $param = Request::param();
            $store_member = db('store_member')->where('cashier_account',$param['cashier_account'])->find();
            if($store_member){
                if(password_verify(trim($param['cashier_pwd']),$store_member['cashier_pwd'])){
                    //登录成功
                    $jwtAuth = JwtAuth::getInstance();
                    $token = $jwtAuth->setUid($store_member['id'])->encode()->getToken();

                    return $this->jsonSuccessData([
                        'token' => $token
                    ]);
                }else{
                    return $this->jsonData();
                    return show(\Yaconf::get('status.error'),'账号或密码错误',[]);
                }
            }else{
                return show(\Yaconf::get('status.error'),'账号或密码错误',[]);
            }
        }else{
            return show(\Yaconf::get('status.error'),'非法请求',[]);
        }
    }
}